<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">

    </avue-crud>
  </basic-container>
</template>

<script>
  import {acceptUserInfo, add, getDetail, getList, refuseUserInfo, remove, update} from "@/api/app/usercheck";
  import {mapGetters} from "vuex";

  export default {
    data() {
      return {
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          height:'auto',
          calcHeight: 30,
          tip: false,
          addBtn:false,
          delBtn: true,
          delBtnText: '审核通过',
          editBtnText: '驳回',
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: false,
          viewBtn: false,
          selection: true,
          dialogClickModal: false,
          updateBtnText: '确认驳回',
          column: [
            // {
            //   label: '头像',
            //   prop: 'avatar',
            //   type: 'upload',
            //   loadText: '附件上传中，请稍等',
            //   listType: "picture-img",
            //   editDisplay: false,
            //   editDisabled: true,
            //   span: 24,
            // },
            {
              hide:true,
              label: "用户ID",
              prop: "id",
              editDisplay: false,
              editDisabled: true,
            },

            {
              label: "真实姓名",
              prop: "name",
              editDisabled: true,
              search: true,
            },

            {
              label: "手机",
              prop: "phone",
              editDisabled: true,
              search: true,
            },

            {
              label: "身份证号",
              prop: "idcard",
              editDisabled: true,
            },
//            {
//              label: "年龄",
//              prop: "ages",
//              rules: [{
//                required: true,
//                message: "请输入年龄",
//                trigger: "blur"
//              }]
//            },
            {
              label: "原部门",
              prop: "oldorg",
              editDisplay: false,
              editDisabled: true,
            },
            {
              label: "原职务",
              prop: "oldpos",
              editDisplay: false,
              editDisabled: true,
            },

            {
              label: "详细地址",
              prop: "address",
              editDisabled: true,
            },
            {
              label: "提交时间",
              prop: "createTime",
              editDisplay: false,
              editDisabled: true
            },
            {
              label: "认证状态",
              prop: "shstatus",
              type: "select",
              editDisabled: true,
              editDisplay: false,
              search: true,
              dicData: [
                {
                  label: "待审核",
                  value: 1
                },
                {
                  label: "认证成功",
                  value: 2
                },
                {
                  label: "已驳回",
                  value: 3
                },
              ],
            },
            {
              label: "审核描述",
              prop: "shdescript",
              type: "textarea",
              span: 24,
            },
          ]
        },
        data: []
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.usercheck_add, false),
          viewBtn: this.vaildData(this.permission.usercheck_view, false),
          delBtn: this.vaildData(this.permission.usercheck_delete, false),
          editBtn: this.vaildData(this.permission.usercheck_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {
      rowUpdate(row, index, done, loading) {
        if (row.shstatus != 1) {
          this.$message({
            type: "warning",
            message: "已处理无需操作!"
          });
          return false;
        }
        refuseUserInfo(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          console.log(error);
        });
      },
      rowDel(row) {
        if (row.shstatus != 1) {
          this.$message({
            type: "warning",
            message: "已处理无需操作!"
          });
          return false;
        }
        this.$confirm("确定审核通过?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return acceptUserInfo(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      rowRefuseUpdate(row, index, done, loading) {
        update(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          console.log(error);
        });
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      }
    }
  };
</script>

<style>
</style>
